home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MISC / SHELL.ARC / Shell / Sources / c / RectSave < prev    next >
Text File  |  1994-11-22  |  4KB  |  176 lines

  1. #include "DeskLib:WimpSWIs.h"
  2. #include "DeskLib:Kbd.h"
  3. #include "DeskLib:Wimp.h"
  4. #include "DeskLib:Window.h"
  5.  
  6. #include "Shell.RectSave.h"
  7. #include "Shell.Save102.h"
  8. #include "Shell.FindWind.h"
  9.  
  10.  
  11.  
  12.  
  13.  
  14. static BOOL Shell_RectSaver( char *filename, void *reference)
  15.     /* This calls the rect's saver, passing the rects info pointer.    */
  16. {
  17. Shell_rectblock    *r = (Shell_rectblock *) reference;
  18.  
  19. if ( !r->saver)    {
  20.     Error_Report( 0, Error_PLACE "Trying to save a rect-type which hasn't got a saver");
  21.     return TRUE;
  22.     }
  23. return (r->saver)( filename, r);
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. static int Shell_RectRAMTransferer(
  32.     task_handle    sourcetask,
  33.     void        *reference,
  34.     task_handle    desttask,
  35.     void        *destbuffer,
  36.     unsigned int    buffersize,
  37.     int        progress
  38.     )
  39.     /* This is just a veneer which casts 'reference' into a (Shell_rectblock *) and then    */
  40.     /* calls the rectangles ramsaver.                            */
  41. {
  42. Shell_rectblock    *r = (Shell_rectblock *) reference;
  43.  
  44. if ( !r->ramsaver)    {
  45.     Error_Report( 0, Error_PLACE "Trying to RAM-transfer a rect-type which hasn't got a RAM transferer");
  46.     return -1;
  47.     }
  48.  
  49. return (r->ramsaver)( sourcetask, r, desttask, destbuffer, buffersize, progress);
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. static BOOL PointInRect(wimp_coord *point, wimp_rect *rectangle)
  58.     /* corrected version of the one in DL    */
  59. {
  60. if ( point->x < rectangle->min.x) return FALSE;
  61. if ( point->x > rectangle->max.x) return FALSE;
  62. if ( point->y < rectangle->min.y) return FALSE;    /* was rectangle->min.x        */
  63.                             /* changed JS Tue 08 Mar 1994    */
  64. if ( point->y > rectangle->max.y) return FALSE;
  65. return TRUE;
  66. }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. static Shell_rectblock    *Shell_FindRectBlockFromPtr( mouse_block *ptrinfo)
  75.     /* Finds the rectblock (if any) that is under the pointer    */
  76. {    Shell_windblock    *w;
  77.     Shell_rectblock    *r;
  78.     window_state    state;
  79.     wimp_point    pos;
  80.  
  81. w = Shell_FindWindBlock( ptrinfo->window);
  82. if (!w)    return NULL;    /* window is not a Shell window    */
  83.  
  84. pos = ptrinfo->pos;
  85. Wimp_GetWindowState( ptrinfo->window, &state);
  86. Coord_PointToWorkArea( &pos, (convert_block *) &state.openblock.screenrect);
  87.  
  88. /* Search backwords so that most recent rects are looked for first.    */
  89. for ( r = LinkList_LastItem( &w->anchor); r; r=LinkList_PreviousItem( &r->header))    {
  90.     if ( PointInRect( &pos, &r->rect))    return r;
  91.     }
  92.  
  93. return NULL;
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100. static BOOL Shell_RectSaveClickHandler( event_pollblock *event, void *reference)
  101.     /* This fn is called whenever there is a click on any window    */
  102.     /* It opens a transient save-window if the click is Shift-Menu    */
  103.     /* 'ref' is the Save_saveblock which was inited by         */
  104.     /* Shell_InitRectSave. We need to fill in the details of the     */
  105.     /* actual rect that was clicked on.                */
  106. {
  107. Shell_rectblock    *r;
  108. mouse_block    ptrinfo;
  109. Shell_Save102_saveblock    *saveblock = (Shell_Save102_saveblock *) reference;
  110.  
  111. if ( !Kbd_KeyDown( inkey_SHIFT)) return FALSE;
  112.  
  113. Wimp_GetPointerInfo( &ptrinfo);
  114. r = Shell_FindRectBlockFromPtr( &ptrinfo);
  115.  
  116. if ( !r) return FALSE;        /* Click wasn't on a rect        */
  117. if ( !r->saver) return FALSE;    /* Click was on a rect, but the        */
  118.                 /* rect hasn't got a save function.    */
  119.                 /* Should really continue the search     */
  120.                 /* in case there is a Shell rect which    */
  121.                 /* is beneath this rect.        */
  122.  
  123.  
  124. saveblock->ref            = (void *) r;
  125. saveblock->estimatedsize    = r->size;
  126. saveblock->ramsaver        = (r->ramsaver) ? Shell_RectRAMTransferer : NULL;
  127.     /* We use the generic Shell savers which call the rect's own saver.    */
  128.  
  129. Shell_Save102_SetFiletype( saveblock, r->filetype);
  130.  
  131. Wimp_CreateMenu(
  132.     (menu_block *) saveblock->window,
  133.     event->data.mouse.pos.x,
  134.     event->data.mouse.pos.y
  135.     );
  136.  
  137. return TRUE;
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. void Shell_InitRectSave(
  146.     char        *windowname,
  147.     icon_handle    dragsprite,
  148.     icon_handle    okbutton,
  149.     icon_handle    cancelbutton,
  150.     icon_handle    filenameicon
  151.     )    {
  152.  
  153. Shell_Save102_saveblock    *saveblock;
  154.  
  155. saveblock = Shell_Save102_InitSaveWindowHandler(
  156.     Window_Create( windowname, 0),
  157.     TRUE,                /* is menu                */
  158.     FALSE,                /* isn't a window            */
  159.     FALSE,                /* don't release handlers after a save    */
  160.     dragsprite,
  161.     okbutton,
  162.     cancelbutton,
  163.     filenameicon,
  164.     Shell_RectSaver,
  165.     NULL,                /* ramsaver filled in later    */
  166.     NULL,                /* result handler        */
  167.     50,                /* est. size            */
  168.     0xfff,                /* Default Filetype.        */
  169.     NULL                /* info                */
  170.     );
  171.  
  172. Event_Claim( event_CLICK, event_ANY, event_ANY, Shell_RectSaveClickHandler, (void *) saveblock);
  173. return;
  174. }
  175.  
  176.